<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>详情</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-
scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/y_index.css" />
    <style>
    .line {
        width: 1rem;
        height: .01rem;
        background: #ccc;
    }
    </style>
</head>

<body>
    <div class="bigBox">
        <div class="container">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <!--    <div class="swiper-slide"><img src="../img/y_6.png"></div>
                    <div class="swiper-slide"><img src="../img/y_6.png"></div> -->
                </div>
                <!-- Add Pagination -->
                <div class="swiper-pagination"></div>
            </div>
            <div class="p20 bw">
                <li class="name">
                    <!-- OBC 无线双耳超小隐形蓝牙耳机挂耳式耳塞迷你入耳式 通用运动跑步  -->
                </li>
                <li class="c1 mt20">￥<span class="font19 price"><!-- 1920.00 --></span></li>
                <li class="col9 mt20">配送方式：<span class="freight"><!-- 快递 --></span><span class="col9 ml100 monthlySales"><!-- 月销200笔 --></span></li>
            </div>
            <div class="bw p20 mt20">分类：<span class="col9 c_name"><!-- 分类1 --></span></div>
            <div class="p20 mt20 flex_aj"><span class="line"></span><span class="mlr20 col9">商品详情</span><span class="line"></span></div>
            <div class="bw p20 flex flex_column remarkImgUrl">
                <div class="remarkImgUrl_a"></div>
                <!-- <img src="../img/y_7.png" style="width:100%;height: 4rem;" /> -->
                <p class="remark">
                    <!-- 文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文 字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字介绍文字 介绍文 -->
                </p>
            </div>
        </div>
        <div class="flex_aj">
            <div class="w50 c_diy flex_aj ptb30" onclick="shopCar()">加入购物车</div>
            <div class="w50 b_diy1 flex_aj ptb30 colw tap" onclick="confirm()">购买</div>
        </div>
    </div>
</body>

</html>
<script src="../js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/dlc.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/swiper.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.0/alipayjsapi.inc.min.js"></script>
<!--公司的常用函数封装-->
<script type="text/javascript">
var price, goodsImgUrl, goodsName, shopArr = [],
    obj = {};
dlc_request('/api/goods/goodsDetails', { id: getUrlParam('id') }, function(res) {
    console.log(res);
    if (res.code == 1) {
        var str = '';
        var str1 = '';
        if (res.goods.carouselImgUrl) { //轮播图（最多5张）
            var list = res.goods.carouselImgUrl.split(',');
            list.forEach((item, index) => {
                str += '<div class = "swiper-slide"><img src = "' + (dlcUrl() + item) + '" style="width:100%;height:4rem;"> </div>'
            })
        }
        price = (res.goods.price * 100) * 1;
        goodsImgUrl = dlcUrl() + getUrlParam('img');
        goodsName = res.goods.name;
        obj.goodsPrice = res.goods.price;
        obj.goodsId = getUrlParam('id');
        obj.goodsNum = 1;
        obj.producer = res.goods.producer;
        obj.freight = res.goods.freight == null ? '0' : res.goods.freight;
        obj.chose = 0;
        obj.imgUrl = goodsImgUrl;
        obj.categoryId = getUrlParam('c_id');
        obj.goodsName = goodsName;
        obj.c_name = decodeURIComponent(getUrlParam('c_name'));
        $('.swiper-wrapper').append(str); //轮播图
        $('.name').text(res.goods.name);
        $('.price').text(Number(res.goods.price).toFixed(2));
        $('.monthlySales').text("月销" + (res.goods.monthlySales == null ? '0' : res.goods.monthlySales) + "笔");
        $('.name').text(res.goods.name);
        $('.c_name').text(decodeURIComponent(getUrlParam('c_name')));
        $('.freight').text(res.goods.freight >= 0 ? '快递' : '免运费');
        if (res.goods.remarkImgUrl) { //商品详情图（最多5张
            var remarkUrl = res.goods.remarkImgUrl.split(',');
            remarkUrl.forEach((item, index) => {
                str1 += '<img src="' + item + '" alt="" />'
            })
            $('.remarkImgUrl_a').html(str1);
        } else {
            $('.remarkImgUrl_a').html(emptyTip('暂无数据'));
        }
        $('.remark').text(res.goods.remark);
        // swiper部分
        var swiper = new Swiper('.swiper-container', {
            autoplay: true,
            loop: true,
            pagination: {
                el: '.swiper-pagination',
            },
        });
    } else {
        dlctipbox.show(res.msg);
    }
})



function shopCar() { //加入购物车
    var status = 0;
    if (getLocalData('shopArr').length > 0) {
        shopArr = getLocalData('shopArr');
        shopArr.forEach((item, index) => {
            if (item.goodsId == obj.goodsId) {
                status = 1;
                if (item.goodsNum == 0) {
                    item.goodsNum = obj.goodsNum;
                }
            }
        })
        if (status == 0) {
            console.log(11);
            shopArr.push(obj);
            // saveLocalData('shopArr', shopArr);
        }
    } else {
        shopArr.push(obj);
        // saveLocalData('shopArr', shopArr);
    }
    saveLocalData('shopArr', shopArr);
    location.href = 'ser_shopCar.html';
}

function confirm() { //购买
    clearLocalData('shopArr');
    var status = 0;
    obj.chose = 1;
    if (getLocalData('shopArr').length > 0) {
        shopArr = getLocalData('shopArr');
        shopArr.forEach((item, index) => {
            item.chose = 1;
            if (item.goodsNum == 0) {
                item.goodsNum = obj.goodsNum;
            }
        })
    } else {
        shopArr.push(obj);
    }
    saveLocalData('shopArr', shopArr);
    location.href = 'ser_confirmOrder.html?sum=' + getLocalData('shopArr')[0].goodsPrice;
}
</script>